package cn.tedu.yushougeproduct.controller;

import cn.tedu.yushouge.commons.web.JsonResult;
import cn.tedu.yushougeproduct.pojo.vo.StateListItemVO;
import cn.tedu.yushougeproduct.pojo.vo.StateStandardVO;
import cn.tedu.yushougeproduct.service.IStateService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/state/")
@Slf4j
@Api(tags = "13：状态管理模块")
@Validated
public class StateController {

    @Autowired
    IStateService iStateService;

    @GetMapping("standard")
    @ApiOperation("根据ID查询状态详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "状态ID", required = true, dataType = "long")
    })
    public JsonResult<StateStandardVO> getStandardById(@Range(min = 1, message = "根据ID查询状态详情失败，请提交合法的ID值！")
                                                              @RequestParam Long id) throws Exception {
        log.debug("开始处理【根据ID查询状态详情】的请求，参数：{}", id);
        StateStandardVO result = iStateService.getStandardById(id);
        return JsonResult.ok(result);
    }

    @GetMapping("list")
    @ApiOperation("查询状态")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<StateListItemVO>> getCartItemDetails() {
        log.debug("开始处理【查询状态列表】的请求");
        List<StateListItemVO> data = iStateService.getStateDetails();
        return JsonResult.ok(data);
    }

}
